package com.dong.ch04_linkedList;

import com.dong.ch03_stack_queue.MyStack;
import com.dong.ch03_stack_queue.Stack;

public class StackLinkedList<E> implements Stack<E> {
    LinkedListDummyHead<E> list = new LinkedListDummyHead();
    @Override
    public void push(E e) {
        list.addFirst(e);
    }

    @Override
    public E pop() {
        return list.removeFirst();
    }

    @Override
    public E peek() {
        return list.getFirst();
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public String toString() {
        return list.toString();
    }
    private static void test1() {
        Stack<Integer> stack = new StackLinkedList<>();
        for (int i = 0; i < 5; i++) {
            stack.push(i);
            System.out.println(stack);
        }
        stack.pop();
        System.out.println(stack);
    }
    public static void main(String[] args) {
        test1();
    }
}
